import "./index.less";
import { useEffect, useRef, useState } from "react";
import { useNavigate } from "react-router-dom";
import { NavBar, Toast } from "antd-mobile";
import ListCard from "./components/listCard";
import { getCurrentUserInfo } from "@/utils/authority";
import { getActivityList } from "../../service";

export default function MyEvents() {
	const navigate = useNavigate();
	const userId = getCurrentUserInfo()?.data?.id;
	const [pageType, setPageType] = useState<string>();

	const [list, setList] = useState<any>([]);

	const detailClick = (data: any) => {
		if (data?.whetherOverdue==0) {
			Toast.show('活动已结束')
			return
		}
		navigate(`/user/trends/MyActivityDetails`,{state:data});
	};
	const getListData = async () => {
		const params = {
			userId: userId,
		};
		try {
			const { data } = await getActivityList(params);
			setList( data );

		} catch {}
	};
	useEffect(() => {
		getListData();
	}, []);

	return (
		<div className="myEvents-contarnier">
			<div className="header">
				<div>
					<NavBar onBack={() => navigate("/user/trends")}>
						<div className="commontitle">我的活动</div>
					</NavBar>
				</div>
			</div>
			<div className="myEvents-box">
				{list?.length > 0 &&
					list?.map((item: any, index: number) => {
						return (
							<ListCard
								data={item}
								detailClick={detailClick}
							/>
						);
					})}
			</div>
		</div>
	);
}
